home *** CD-ROM | disk | FTP | other *** search
- on parse chunk, alistcast
- set l to chunk
- set out to EMPTY
- set alist to [0: #null]
- set i to 1
- repeat while not (l = EMPTY)
- if char 1 of l = "<" then
- delete char 1 of l
- set tag to EMPTY
- repeat while not ((l = EMPTY) or (char 1 of l = ">"))
- if char 1 of l = QUOTE then
- set tag to tag & QUOTE & ""E&" & QUOTE
- else
- set tag to tag & char 1 of l
- end if
- delete char 1 of l
- end repeat
- addProp(alist, i, tag)
- if not (l = EMPTY) then
- delete char 1 of l
- end if
- next repeat
- end if
- set out to out & char 1 of l
- delete char 1 of l
- set i to i + 1
- end repeat
- deleteProp(alist, 0)
- set the text of cast alistcast to string(parse2(alist))
- return out
- end
-
- on parse2 alist
- addProp(alist, #null, "0")
- set i to 1
- repeat while not (getPropAt(alist, i) = #null)
- set tag to getAt(alist, i)
- if nameof(tag) = "a" then
- set closed to 0
- put i & "anchor tag opened: " & QUOTE & restof(tag) & QUOTE
- setAt(alist, i, restof(tag))
- set i to i + 1
- repeat while not closed
- set tag to getAt(alist, i)
- if nameof(tag) = "/a" then
- set closed to 1
- put i & "anchor tag closed"
- setAt(alist, i, EMPTY)
- set i to i + 1
- next repeat
- end if
- if getPropAt(alist, i) = #null then
- put "warning: eof and tag not closed."
- put i & " Forcing closed"
- deleteProp(alist, #null)
- addProp(alist, 25000, EMPTY)
- addProp(alist, #null, "0")
- set closed to 1
- set i to i + 1
- next repeat
- end if
- put "tag not closed, ignoring tag: " & QUOTE & nameof(tag) & QUOTE
- deleteAt(alist, i)
- end repeat
- next repeat
- end if
- put "unknown tag " & QUOTE & nameof(tag) & QUOTE
- deleteAt(alist, i)
- end repeat
- deleteProp(alist, #null)
- return alist
- end
-
- on nameof t
- return car_(stripfrombegining(t, " "), " ")
- end
-
- on restof t
- return stripfrombegining(cdr_(stripfrombegining(t, " "), " "), " ")
- end
-
- on car_ l, delimiter
- set save to the itemDelimiter
- set the itemDelimiter to delimiter
- set a to item 1 of l
- set the itemDelimiter to save
- return a
- end
-
- on cdr_ l, delimiter
- set save to the itemDelimiter
- set the itemDelimiter to delimiter
- delete item 1 of l
- set the itemDelimiter to save
- return l
- end
-
- on stripfrombegining l, a
- if char 1 of l = a then
- repeat while char 1 of l = a
- delete char 1 of l
- end repeat
- end if
- return l
- end
-